<?Lassoscript
// Last modified 11/30/09 by Eric Landmann

// FUNCTIONALITY
// Include file used in response page to for Users

// CHANGE NOTES
// 11/30/09
// First implementation

// Debugging
Var:'svDebug' = 'Y';

// Converting action_params
Var:'vError' = '';
Var:'vOption' = '';
// The action_param "Action" is passed by the frm_user.inc form to indicate whether it is an add or edit
// Action = Update, means the request was an Edit (from frm_user.inc)
// Action = Add, means the request was an Add (from frm_user.inc)
Var:'vAction' = (Action_Param:'Action');

If: $svDebug == 'Y';
	'<br>\r';
	'<strong>user_addresponse.inc</strong><br>\r';
/If;

// Checking Action to make sure it's only posting from the Add page
// ============= ADD ========
If: $vAction == 'Add';

	// THERE IS NO ADD - this must be done through signup

// ============= EDIT ========
// Action = Update, means the request came from the Edit page
Else: $vAction == 'Update';

	// Convert action_params
	Include:($svLibsPath)'user_params.inc';

	// If an error was generated from the Params, no point continuing, so bail immediately
	If: $vError == '';

		// Construct the query to Update the User
		// Not changing the Date_Created fields
		// NOTE: TID and SID are NOT IMPLEMENTED at this time
		Var:'SQLUpdateUser' = ('UPDATE ' $svMembersTable ' SET 
First_Name = "'($vFirst_Name)'",
Last_Name = "'($vLast_Name)'",
Post_Name1 = "'($vPost_Name1)'",
Post_Name2 = "'($vPost_Name2)'",
Post_Name3 = "'($vPost_Name3)'",
Post_Name4 = "'($vPost_Name4)'",
Post_Name5 = "'($vPost_Name5)'",
Pass = "'($vPass)'",
Mail = "'($vMail)'",
Fav_Crag = "'($vFav_Crag)'",
Address = "'($vAddress)'",
City = "'($vCity)'",
State = "'($vState)'",
Zip = "'($vZip)'",
Country = "'($vCountry)'",
Phone = "'($vPhone)'",
Fav_URL = "'($vFav_URL)'",
Sex = "'($vSex)'",
Year_Born = "'($vYear_Born)'",
Type = "'($vType)'",
Ability = "'($vAbility)'",
Achieve = "'($vAchieve)'",
Statement = "'($vStatement)'",
Email_Forum1 = "'($vEmail_Forum1)'",
Email_Forum2 = "'($vEmail_Forum2)'",
Email_Forum3 = "'($vEmail_Forum3)'",
Email_Forum4 = "'($vEmail_Forum4)'",
Email_Forum5 = "'($vEmail_Forum5)'",
Email_Forum6 = "'($vEmail_Forum6)'",
Email_Forum7 = "'($vEmail_Forum7)'",
Email_Forum8 = "'($vEmail_Forum8)'",
Email_Forum9 = "'($vEmail_Forum9)'",
Email_Forum10 = "'($vEmail_Forum10)'",
Email_Forum11 = "'($vEmail_Forum11)'",
Email_Forum12 = "'($vEmail_Forum12)'",
Allow = "'($vAllow)'" 
WHERE ID = "' $vID '"');

		Debug;
			'224: SQLUpdateUser = ' $SQLUpdateUser '<br>\n';
			'224: Error = ' (Error_CurrentError) '<br>\n';
		/Debug;
	
		Inline: $IV_SearchMembers, -SQL=$SQLUpdateUser;
			
			If:(Error_CurrentError)==(Error_NoError);
		
				// If no error, Update was successful, dump out Error 5022 "Update Successful"
				Var:'vError' = '5022';
				Var:'vOption' = 'user';
				Debug;
					'233: vError = ' $vError '<br>\n';
					'233: vOption = ' $vOption '<br>\n';
				/Debug;
		
			// There was an error
			Else;
				Var:'vError' = (Error_CurrentError);
			/If;
		
		/Inline;

		// vError == ''
		/If;
		
// ============= DELETE ========
Else: $vAction == 'Delete';

	// Convert action_params
	Var:'vID'=(Action_Param:'ID');
		
	// Build the Delete Query
	Var:'SQLDeleteQuery' = (string);
	Var:'SQLDeleteQuery' = 'DELETE FROM ' $svSiteDatabase'.'$svMembersTable ' WHERE ID = "' $vID '"';
	
	// Delete the record
	Inline: $svMembersTable, -SQL=$SQLDeleteQuery;
		// If delete successful, output 5024 "Deletion Successful"
		If: (Error_Code) == '0';
			Var:'vError' = '5024';
			Var:'vOption' = $vID;

		Else;
			Var:'vError' = '5025';
			Var:'vOption' = (Error_CurrentError);
			Var:'URL' = ('setup_editrecord.lasso?DataType=User&Error='$vError'&Option='$vOption);
			If: $svDebug == 'Y';
				'175: URL = ' $URL '<br>\n';
				'<a href="'$URL'">' $URL '</a><br>\n';
			Else;
				Redirect_URL: $URL;
			/If;
		/If;
	/Inline;

// Referrer not good, somebody is messing with us
// Dump out error 9002, "Database Error"
Else;
	Var:'vError' = '9002';
/If;


// Deal with the results of the processing
// ============= EDIT ========
// If vAction = Edit, Always redirect to edit page
// If record updated OK, will get a 5022 "Update Successful" message, but do NOT pass the Params, only the ID
// This forces the system to do a new lookup
If: $vAction == 'Update';
	If: (Var:'vError') == '5022';
		Var:'URL' = ('setup_editrecord.lasso?DataType=User&ID='$vID'&New=Y&Error='$vError'&Option='$vOption);
	Else;
		Var:'URL' = ('setup_editrecord.lasso?New=Y&Error='$vError'&Option='$vOption'&'(Client_POSTArgs));
	/If;
	If: $svDebug == 'Y';
		Debug;
			'294: URL = ' $URL '<br>';
			'<a href="'$URL'">' $URL '</a><br>\n';
		/Debug;
	Else;
		Redirect_URL: $URL;
	/If;
/If;

// ============= DELETE ========
// If Action = Delete, redirect to User Search page
If: $vAction == 'Delete';
	Var:'URL' = ('setup_edit.lasso?Datatype=User&Error='$vError'&Option='$vOption);
	If: $svDebug == 'Y';
		Debug;
			'239: URL = ' $URL '<br>';
			'<a href="'$URL'">' $URL '</a><br>\n';
		/Debug;
	Else;
		Redirect_URL: $URL;
	/If;
/If;
?>
